package routers

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/swaggo/gin-swagger"
	"github.com/swaggo/gin-swagger/swaggerFiles"
	_ "tapi-go/docs"
	"tapi-go/global"
	"tapi-go/global/response"
	v1 "tapi-go/routers/api/v1"
	"tapi-go/routers/group"
)

// 初始化总路由

func InitRouters() *gin.Engine {
	var Router = gin.Default()

	//router.Static("/doc", "./doc")
	//router.StaticFS("/more_static", http.Dir("my_file_system"))
	// Router.Use(middleware.LoadTls())  // 打开就能玩https了
	global.YY_LOG.Info("use middleware logger")
	// 跨域
	//Router.Use(middleware.Cors())
	//global.YY_LOG.Info("use middleware cors")

	Router.GET("/", func(c *gin.Context) {
		address := fmt.Sprintf(":%d", global.YY_CONFIG.System.Addr)
		response.OkWithMessage("hello world"+address, c)
	})
	Router.GET("/getToken", v1.GetToken)                                      // 获取token
	Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) //api 文档
	// 方便统一添加路由组前缀 多服务器上线使用
	ApiGroup := Router.Group("")
	group.InitUserRouter(ApiGroup)
	global.YY_LOG.Info("router register success")
	return Router
}
